﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Ccit.Utils;

namespace Ccit.Global
{
    public class SessionExt
    {
        /// <summary>
        /// 获取6个大字段
        /// </summary>
        /// <returns></returns>
        public static string GetSysFieldXML()
        {
            LoginUser oLgUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            StringBuilder sb = new StringBuilder();

            sb.Append("<ORGANID>").Append(oLgUser.OrganId).Append("</ORGANID>");
            sb.Append("<DEPTID>").Append(oLgUser.DeptId).Append("</DEPTID>");
            sb.Append("<POSID>").Append(oLgUser.PosId).Append("</POSID>");
            sb.Append("<CLASSID>").Append(oLgUser.ClassId).Append("</CLASSID>");
            sb.Append("<USERID>").Append(oLgUser.UserId).Append("</USERID>");
            sb.Append("<CREATETIME>").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Append("</CREATETIME>");
            oLgUser = null;
            return sb.ToString();
        }

        /// <summary>
        /// 获取系统6个字段的SQL形式
        /// </summary>
        /// <param name="sTableName">表名</param>
        /// <returns>
        ///    索引0: insert 语句的片段
        ///    索引1: value 值片段
        /// </returns>
        public static string[] GetSysFieldSQL(string sTableName)
        {
            string[] sRetSQL = new string[2];
            StringBuilder sbInsert = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();
            sbInsert.Append(sTableName).Append("_9990,").Append(sTableName).Append("_9991,");
            sbInsert.Append(sTableName).Append("_9992,").Append(sTableName).Append("_9993,");
            sbInsert.Append(sTableName).Append("_9994,").Append(sTableName).Append("_9995");

            LoginUser oLgUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
            string sOrganId = (oLgUser.OrganId == "") ? "null" : oLgUser.OrganId;
            string sDeptId = (oLgUser.DeptId == "") ? "null" : oLgUser.DeptId;
            string sPosId = (oLgUser.PosId == "") ? "null" : oLgUser.PosId;
            string sClassId = (oLgUser.ClassId == "") ? "null" : oLgUser.ClassId;

            sbValue.Append(sOrganId).Append(",").Append(sDeptId).Append(",");
            sbValue.Append(sPosId).Append(",").Append(sClassId).Append(",");
            sbValue.Append(oLgUser.UserId).Append(",'").Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm")).Append("'");
            oLgUser = null;

            sRetSQL[0] = sbInsert.ToString();
            sRetSQL[1] = sbValue.ToString();

            return sRetSQL;
        }
    }
}
